#coding:utf-8
import requests
import json
from lxml import etree
# import pymysql
def _getMiddleStr(start_str, end, html):
    start = html.find(start_str)
    if start >= 0:
        start += len(start_str)
        end = html.find(end, start)
        if end >= 0:
            return html[start:end].strip()
UA = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"}
def getComicid(url):
	html = requests.get(url).text
	g_current_id = _getMiddleStr('var g_current_id = "','";',html)
	return g_current_id
def getComments(rid,page=1):
	html = requests.get(("https://comment.dmzj.com/v1/4/latest/%s?callback=comment_list_s&page_index=%s")%(rid,page),headers=UA).text
	json_raw = html[len("/**/comment_list_s("):len(html)-2]
	results = json.loads(json_raw)
	return results
def getComicInfomation(url):
	pass
def getUserComicSubscribe(uid,page=1):
	raw = requests.get("https://i.dmzj.com/otherCenter/hisSubscribe?hisUid="+uid,headers=UA).text
	raw = etree.HTML(raw)
	rightFlag = raw.xpath("//input[@id='rightFlag']")
	rightLevel = raw.xpath("//input[@id='rightLevel']")
	# print rightLevel[0].attrib["value"]
	html = requests.post("https://i.dmzj.com/otherCenter/ajaxGetHisSubscribe",data={
		"page":page,
		"type_id":"1",
		"letter_id":"0",
		"hisUid":uid,
		"read_id":"1",
		"rightFlag":rightFlag[0].attrib["value"],
		"rightLevel":rightLevel[0].attrib["value"]
		},headers=UA).text
	return html
def parserSuvscribeComicInfomation(result):
	pass
print getUserComicSubscribe("104492535")